package middle;

public class Solution_153 {

    public int findMin(int[] nums) {
        /*int min = nums[0];
        for (int num : nums) {
            min = Math.min(min, num);
        }
        return min;*/
        int begin = 0, end = nums.length - 1;
        while ((begin + 1) < end) {
            int middle = (begin + end) >> 1;
            if (nums[middle] > nums[begin] && nums[middle] < nums[end]) {
                return nums[begin];
            } else if (nums[middle] > nums[begin] && nums[middle] > nums[end]) {
                begin = middle + 1;
            } else if (nums[middle] < nums[begin] && nums[middle] < nums[end]) {
                end = middle;
            }
        }
        return Math.min(nums[begin], nums[end]);
    }

    public static void main(String[] args) {
        Solution_153 model = new Solution_153();
        System.out.println(model.findMin(new int[]{11, 13, 15, 17}));
        System.out.println(model.findMin(new int[]{15, 17, 11, 13}));
        System.out.println(model.findMin(new int[]{13, 15, 17, 11}));
    }
}
